package com.econ.powercloud.ems.dal.mapper;

import com.econ.powercloud.ems.dal.entity.EmsProtectSoeEventRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * ems保护事件/SOE事件记录表 Mapper 接口
 * </p>
 *
 * @author AutoGenerator
 * @since 2022-08-03
 */
public interface EmsProtectSoeEventRecordMapper extends BaseMapper<EmsProtectSoeEventRecord> {


    @Select("<script>" +
            " SELECT r.*" +
            " FROM ems_protect_soe_event_record r" +
            " INNER JOIN (" +
            " SELECT device_code,MAX(gmt_create) as gmt_create" +
            " FROM ems_protect_soe_event_record" +
            " WHERE event_type = #{eventType}" +
            " GROUP BY device_code" +
            " ) a ON r.device_code = a.device_code AND r.gmt_create = a.gmt_create" +
            "</script>")
    List<EmsProtectSoeEventRecord> selectLeastRecordWithDeviceByCondition(@Param("eventType") Integer eventType);

}
